'use strict';

/**
 * @name SpaceDetailEditCtrl
 * @author ZYF
 */

angular.module('metalabOperationApp').controller('SpaceDetailEditCtrl', ['$scope', '$rootScope', '$state', '$stateParams', 'MetaResources', 'MetaRemind', 'MetaEdit', function ($scope, $rootScope, $state, $stateParams, MetaResources, MetaRemind, MetaEdit) {
    $scope.editCtrl = {
        data: {}
    };
    $scope.editAreasCtrl = {
        data: {}
    };
    $scope.editAchievementsCtrl = {
        data: {}
    };
    $scope.spaceChange = function (index) {
        var urlParams = {
            id: $stateParams.id,
            tab: index
        };
        $state.go('meta.permission.research.space.detail', urlParams);
    };
    $scope.init = function() {
        $scope.spaceStatus = 0;
        MetaEdit.initEditModule($scope, $stateParams, 'talent', 'user');
    };
    $scope.save = function () {
        var value = angular.copy($scope.editCtrl.data);
        value.id = undefined;
        MetaResources.talent.save({
                'id': $scope.editCtrl.data.userId
            }, value,
            function () {
                MetaRemind.success("恭喜", "修改成功");
                MetaEdit.syncData($scope.editCtrl, 'talent');
            },
            function (error) {
                MetaRemind.serverError(error);
            });
    };
    $scope.toBeContinued = MetaRemind.error;
    $scope.init();
}]);
